package merlin.utils;

import java.io.*;
import java.util.*;

public class ApplicationResources  {
	private static ApplicationResources instance;
	private static Properties prop;

	/**
	 * Private constructor to initialize the Properties object by reading the data from the properties file.
	 */
	private ApplicationResources()throws IOException{
		prop = new Properties();
		// load the application-related information
		//prop.load(this.getClass().getResourceAsStream("application.properties"));
		prop.load(this.getClass().getClassLoader().getResourceAsStream("merlin/utils/application.properties"));
	}

	/**
	 * Do-nothing constructor
	 */
  	private ApplicationResources(String str){
  	}
	/**
	 * Returns the singleton instance.
	 */
	public static ApplicationResources getInstance(){
		try{
			if(instance == null){
				instance = new ApplicationResources();
			}
		}catch(Exception e){
			instance = new ApplicationResources(null);
			System.err.println("ApplicationResources :init: " + e);
		}
		return instance;
	}

	/**
	 * Returns the value based on the key
	 */
	public String getProperty(String key){
		if(key == null)
			return null;
		else
			return prop.getProperty(key);
	}

	/**
	 * Returns the value based on the key otherwise the default value
	 */
	public String getProperty(String key,String defaultValue){
		if(key == null)
			return null;
		else
			return prop.getProperty(key,defaultValue);
	}
}